<template>
	<view class="wrap">

		<view class="scroll-list msg-list-item">
			<view v-for="(item, index) in message" :key="index">
				<view class="msg-time">{{ item.creatTime }}</view>
				<u-card :title="item.title " :sub-title="item.creatTime" padding="20" margin="0rpx 10rpx"
					thumb="../../../../static/list-icon.png" @click="go(item,index)">
					<view class="" slot="body">
						<view class="u-body-item u-flex  u-col-between u-p-t-0">
							<view class="u-body-item-title u-line-2">
								{{ item.text | delHtmlTag }}
							</view>
						</view>
					</view>
				
				</u-card>
			</view>
			
	

			<uni-load-more :status="status" :icon-size="14" :content-text="contentText" />

		</view>
	</view>
</template>
<script>
	import uCard from '../../../../components/u-card/u-card.vue'

	export default {
		data() {
			return {
				message: [

				],
				Page: {
					pageSize: 10,
					pageIndex: 1
				},
				reload: false,
				status: 'more',
				contentText: {
					contentdown: '上拉加载更多~',
					contentrefresh: '加载中',
					contentnomore: '我是有底线的~'
				},
				totalCount: 0


			};
		},
		onReachBottom() {
			if (this.totalCount > this.message.length) {
				this.status = 'loading';
				setTimeout(() => {
					console.log("我是定时器");
					this.Page.pageIndex++
					this.init(); //执行的方法
				}, 1000)
				console.log("我比定时器先执行");
			} else { //停止加载
				this.status = 'noMore'
			}
				
		},
		onLoad() {
			this.init();
		},
		components: {
			uCard
		},
		methods: {
			go(item,index)
			{	
				if (item.status == 1) {
					 uni.$u.http
						.get(`/app/message/update/` + item.id)
							this.message[index].status = 2
							console.log(this.message[index]);
				}
				uni.navigateTo({
					url: '/pages/fun/message/from/from?id=' + item.id
				})
			},
			
		
			
			init() {
				uni.$u.http
					.get('/app/message/getMessage/' + this.Page.pageIndex + '/' + this.Page.pageSize)
					.then(res => {
						this.totalCount = res.data.total
						if (res.data.total > 0) {
							const dataMap = res.data.records
							this.message = this.reload ? dataMap : this.message.concat(dataMap);
							this.reload = false;
						} else {
							this.message = [];
						}
						if (this.totalCount == this.message.length) {
							this.reload = false;
							this.status = 'noMore'
						}
					})
		
			}
		},

	};
</script>
<style lang="scss">
	page {
		background-color: #f5f5f5;
	}

	.wrap .search {
		background: #ffffff;
	}

	.msg-time {
		font-size: 26rpx;
		padding: 10px 0;
		color: #999999;
		text-align: center;
	}

	.u-card__foot {
		.u-icon {
			margin-right: 10px;
		}
	}
</style>
